Visual Color Picker

Posted by apoorvas

apoorvas's picture

 

Description:

To learn about the digital features of the Arduino Board. Our lab would include learning about Pulse Width Modulation(for faking Analog behavior using Digital signals) and Serial communication with the laptop.

 

Components Used:

  • 3 LEDs(Red, Blue, Green)

  • Arduino Micro-controller

  • 3 Resistors (220 Ohms)

  • Wires/Bread Board

  • Diffuser

Diffuser:

In Lab, different materials were used as diffusers to give a color mix of the RGB LEDs. I used cotton layers to diffuse light. Anything that was not too transparent and not too thick did  a good job of disffusing the light.

 

Input Method:

 

I wanted to make a visual color palette so that once your roll your mouse over, the leds change brightness in order to create the color being choosen. I used the processing program to create the GUI as that is what was recommended in the Arduino Communications example. So I am enclosing both the codes here :-

 

Arduino Code: 

 

int rPin = 9;

int gPin = 10;

int bPin = 11;

int serialColors[3]; //array to store values from serial port

int serialCount = 0;

char val;

 

int rByte;

int gByte;

int bByte;

 

void setup()

{

  Serial.begin(9600);

  pinMode(rPin, OUTPUT);

  pinMode(gPin, OUTPUT);

  pinMode(bPin, OUTPUT);

}

 

void loop()

{

  if (Serial.available() > 0) {

    

    serialColors[serialCount] = Serial.read();

    serialCount++;

    

    if (serialCount > 2) {

      rByte = serialColors[0];

      gByte = serialColors[1];

      bByte = serialColors[2];

      Serial.println(rByte);

      analogWrite(rPin, rByte);

      analogWrite(gPin, gByte);

      analogWrite(bPin, bByte);

      

      serialCount = 0;

    }

  }

}

 

Processing Code:- 

import processing.serial.*;

 

Serial port; 

float xmag, ymag = 0;

float newXmag, newYmag = 0;

 

void setup() 

  

  size(255, 255); 

   noStroke(); 

   colorMode(HSB, 255);   //sets the color scheme to be displayed on screen 

 

  frameRate(10); 

  for(int i=0; i<255; i++) {

    for(int j=0; j<255; j++) {

      stroke(i, j, 255);

      point(i, j);

    }

  }

 

  // Open the port that the Arduino board is connected to (in this case #0) 

  // Make sure to open the port at the same speed Arduino is using (9600bps) 

  port = new Serial(this, Serial.list()[0], 9600); 

}

 

float getRed() 

  return red(get(mouseX,mouseY));

 

}

 

float getGreen() 

  return (green(get(mouseX,mouseY)));

 

}

 

float getBlue()

{

  return (blue(get(mouseX,mouseY)));

}

 

void draw() 

  int r = 0;

  int g = 0;

  int b = 0;

  r = int(getRed());

  g = int(getGreen());

  b = int(getBlue());

  //  println("r =" + r);

  //  println("g =" + g);

  //  println("b =" + b);

 

  port.write(r);

  port.write(g);

  port.write(b);

 

}  

video:

http://www.youtube.com/watch?v=e2ygvinFKvM

 Source : http://processing.org/reference/colorMode_.html   

The Actual Circuit
Screenshot.PNG
IMG_9558.jpg
IMG_9556_1.jpg
0
Your rating: None